//
//  NSObject+HYC_Tools.m
//  HYC_TOOLS_OC
//
//  Created by HYC on 2023/3/17.
//

#import "NSObject+HYC_Tools.h"
#import <objc/runtime.h>

@implementation NSObject (HYC_Tools)
///获取属性列表
+ (NSMutableArray <NSString *>*)H_RunTime_ProprtyList {
    unsigned int count;
    
    NSMutableArray <NSString *>*arr = [NSMutableArray arrayWithCapacity:0];
    
    objc_property_t *propertyList = class_copyPropertyList([self class], &count);
    for (unsigned int i = 0; i < count; i++) {
        const char *propertyName = property_getName(propertyList[i]);
        NSLog(@"propertyName(%d) --- %@", i, [NSString stringWithUTF8String:propertyName]);
        
        [arr addObject:[NSString stringWithUTF8String:propertyName]];
    }
    free(propertyList);
    
    
    

    return arr;
    
}

///获取成员变量列表
+ (NSMutableArray <NSString *>*)H_RunTime_IvarList {
    unsigned int count = 0;
    
    NSMutableArray <NSString *>*arr = [NSMutableArray arrayWithCapacity:0];
    
    objc_property_t* propertys = class_copyPropertyList([self class], &count);
    for (unsigned int i = 0; i < count; i++) {
        objc_property_t property = propertys[i];
        assert(property != nil);
        const char* name = property_getName(property);
        NSLog(@"name: %s", name);

        NSString* attrs = @(property_getAttributes(property));
        NSLog(@"artStr: %@", attrs);
        
        [arr addObject:attrs];
    }
    
    
//    NSString *const TypeInt = @"i"; 整数类型
//    NSString *const TypeShort = @"s"; 双字节类型
//    NSString *const TypeFloat = @"f"; float 浮点型
//    NSString *const TypeDouble = @"d"; double 双精度浮点型
//    NSString *const TypeLong = @"l"; long 长整型
//    NSString *const TypeLongLong = @"q";
//    NSString *const TypeChar = @"c"; char 单字节类型
//    NSString *const TypeBOOL1 = @"c"; bool 类型
//    NSString *const TypeBOOL2 = @"b"; bool 类型
//    NSString const TypePointer = @""; 指针类型
//    NSString *const TypeIvar = @"^{objc_ivar=}";
//    NSString *const TypeMethod = @"^{objc_method=}"; oc 方法类型
//    NSString *const TypeBlock = @"@?"; oc 闭包类型
//    NSString *const TypeClass = @"#"; oc class 类类型
//    NSString *const TypeSEL = @":"; oc slector 触发器方法类型
//    NSString *const TypeId = @"@"; oc 泛型id类型

    return arr;
}

///获取类的方法列表
+ (NSMutableArray <NSString *>*)H_RunTime_MethodList {
    unsigned int count;
    
    NSMutableArray <NSString *>*arr = [NSMutableArray arrayWithCapacity:0];
    
    Method *methodList = class_copyMethodList([self class], &count);
    for (unsigned int i = 0; i < count; i++) {
        Method method = methodList[i];
        NSLog(@"method(%d) --- %@", i, NSStringFromSelector(method_getName(method)));
        [arr addObject:NSStringFromSelector(method_getName(method))];
    }
    free(methodList);
    
    return arr;
}
@end
